package com.ccx.library.export;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.read.listener.PageReadListener;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.function.Function;

/**
 * 加载excel
 */
@Slf4j
public class LoadExcel<T> {

    // 读取加载excel
    public void ReadExcel(String fileName, Class cls, Function<List<T>, Object> function) {
        EasyExcel.read(fileName, cls, new PageReadListener<T>(dataList -> {
            new Thread(() -> {
                for (T t : dataList) {
                    log.info("读取中:{}", JSON.toJSONString(t));
                }
            }).start();
            function.apply(dataList);
        })).sheet().doRead();
    }
}
